﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CommonUtility
{
   public enum CompareType
    {
        CourseId,
        CourseName,
        CourseStatus,
       TeacherName,
       LevelName,
       StudentNumber
    }
    public class CourseListComparer:IComparer<TrainingWorkshop.Model.CourseList>
    {

        
        private CompareType _compareColumn;

        public CompareType CompareColumn
        {
            get { return _compareColumn; }
            set { _compareColumn = value; }
        }

        public CourseListComparer(CompareType t) {
            this._compareColumn = t;

        }

        /// <summary>
        /// compare by different property
        /// </summary>
        /// <param name="x">CourseList x</param>
        /// <param name="y">CourseList y</param>
        /// <returns>int </returns>
        public int Compare(TrainingWorkshop.Model.CourseList x,TrainingWorkshop.Model.CourseList y) {

            //CompileType sort = (CompileType)Enum.Parse(typeof(CompileType), "ID");
            switch (this.CompareColumn) { 
                case CompareType.CourseId:
                    return x.CourseId.CompareTo(y.CourseId);
                case CompareType.CourseName:
                    return x.CourseName.CompareTo(y.CourseName);
                case CompareType.CourseStatus:
                    return x.CourseStatus.CompareTo(y.CourseStatus);
                case CompareType.TeacherName:
                    return x.TeacherName.CompareTo(y.TeacherName);
                case CompareType.LevelName:
                    return x.LevelName.CompareTo(y.LevelName);
                case CompareType.StudentNumber:
                    return x.StudentNumber.CompareTo(y.StudentNumber);
                default: return x.CourseId.CompareTo(y.CourseId); 

            }
        } 
    }
}
